<?php 
 require_once("konf.php"); 
 if(!empty($_REQUEST["lisakogus"])){
 $kask=$yhendus->prepare(
 "UPDATE joogid SET kogus=kogus+? WHERE id=?");
$kask->bind_param("ii", $_REQUEST["lisakogus"], $_REQUEST["id"]);
$kask->execute();
header("Location: $_SERVER[PHP_SELF]");
 }
 if(!empty($_REQUEST["uuskogus"])){
 $kask=$yhendus->prepare(
 "UPDATE joogid SET kogus=? WHERE id=?");
$kask->bind_param("ii", $_REQUEST["uuskogus"], $_REQUEST["id"]);
$kask->execute();
header("Location: $_SERVER[PHP_SELF]");
 }

	$kask=$yhendus->prepare("SELECT id, jooginimi, kogus 
	FROM joogid");
	$kask->bind_result($id, $jooginimi, $kogus);
	$kask->execute();

?>
<!doctype html>
<html>
 <head>
 <link rel="stylesheet" type="text/css" href="stiil.css">
 <title>Baarikapp</title>
 </head>
 <body>
 <div id="p2is">
	 <h1>Baarikapi admin</h1>
	 <?php
		require_once("pais.php"); 
	 ?>
	 <p> 1l = 100cl </p>
 </div>
 <div id="joogitabel">
 <table border="1">
 <tr>
	 <th>Jook</th>
	 <th>Kogus (cl)</th>
	 <th>Lisamine / Muutmine</th>
 </tr>
 <?php
 while($kask->fetch()){
 echo "
 
 <tr>
 <td>$jooginimi</td>
 <td ";
 if ($kogus<50){
	echo"style='color:red;'";
	}
  echo ">$kogus</td>
 <td><form action=''>
 <input type='hidden' name='id' value='$id' />
 <input type='text' name='lisakogus' class='textbox'/> <input type='submit' value='Lisa (cl)' />
 <input type='text' name='uuskogus' class='textbox'/> <input type='submit' value='Sisesta uus väärtus (cl)' />
 </form>
 </td>
</tr>
 ";
}
 ?>
</table>
</div>
 </body>
</html>
<?php 
	$yhendus->close();
?>
